﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mogre;

namespace WastedMechanics
{
    class EditorCamera
    {
        public float Speed = 0.2f;
        public void Update()
        {
            if (Engine.Keyboard.IsKeyDown(MOIS.KeyCode.KC_W))
                Engine.Camera.Position += Engine.Camera.Direction * Speed;
            if (Engine.Keyboard.IsKeyDown(MOIS.KeyCode.KC_S))
                Engine.Camera.Position -= Engine.Camera.Direction * Speed;
            if (Engine.Keyboard.IsKeyDown(MOIS.KeyCode.KC_A))
                Engine.Camera.Position -= Engine.Camera.Right * Speed;
            if (Engine.Keyboard.IsKeyDown(MOIS.KeyCode.KC_D))
                Engine.Camera.Position += Engine.Camera.Right * Speed;
            if (Engine.Keyboard.IsKeyDown(MOIS.KeyCode.KC_SPACE))
            {
                Raycaster.PredicateRaycast raycast = new Raycaster.PredicateRaycast(
                    (MogreNewt.Body body) => {return body.UserData is Character;}
                );
                Vector3 start = Engine.Camera.Position;
                Vector3 end = Engine.Camera.Position + Engine.Camera.DerivedDirection * 30 ;
                raycast.Go(Engine.NewtonWorld, start, end);
                raycast.SortContacts();
                if (raycast.Contacts.Count > 0) {
                
                    ((Character)raycast.Contacts[0].Body.UserData).Position = Engine.Camera.Position;

                }
            }


            Engine.Camera.Yaw(new Degree(90 * -Engine.MouseInput.Delta.x));
            Engine.Camera.Pitch(new Degree(90 * -Engine.MouseInput.Delta.y));        
        }
    }
}
